﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using abc_ns;
namespace ece750project
{
    public partial class Loginfrm : Form
    {
		static int x1(string s)
		{
			MessageBox.Show(s);
			return 0;
		}
		
		int x2(string s)
		{
			MessageBox.Show(s +"/ Heloo the second");
				
			return 0;
		}

		public Loginfrm()
        {
            InitializeComponent();
            //DB = new DB_BusinessRules();
        }

    

     

        private void Form1_Load(object sender, EventArgs e)
        {
            //DBUtility
        }


        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtpassword_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                
            }
        }





        private void btnLogin_Click(object sender, EventArgs e)
        {
            int P_ID;
            P_ID = DBUtility.Login(txtusername.Text, txtpassword.Text);
            if (P_ID  == 0)
            {
                abc_app.msgbox("Faild to login to the database server\n be sure that you entered the correct user name and password.", "Login", Microsoft.VisualBasic.MsgBoxStyle.Critical);

            }
            else
            {
                DataTable DT;
                DT = DB_BusinessRules.Get_person(P_ID.ToString());
                abc_class.person_Struct_Load(ref abc_app.current_user_personal_info, ref DT, 0);
                
                switch ((Person_type) abc_app.current_user_personal_info.person_type)
                {
                    case Person_type.Patiernt:
                        abc_app.msgbox("Patients should login using the web interface !", "Login", Microsoft.VisualBasic.MsgBoxStyle.Critical);
                        break;

                    case Person_type.Doctor:
                        DoctorMain f = new DoctorMain();
                        f.para.Doc_id = abc_app.current_user_personal_info.person_id;
                        this.Hide();
                        f.ShowDialog();
                        break;

                    case Person_type.Staff:
                        Staff st = new Staff();
                        this.Hide();
                        st.ShowDialog();
                        break;
                    case Person_type.Finance:
                        Finance fn = new Finance();
                        fn.para.Finance_id = abc_app.current_user_personal_info.person_id;
                        this.Hide();
                        fn.ShowDialog();

                        break;
                }
                this.Show();
                txtpassword.Text = "";
                txtusername.Text = "";
				this.Text="Loged out";
            }
            

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //abc_app.permitDoctors_para.Doc_id = 3;
            //abc_app.permitDoctors_para.Patient_id = 8;
            //abc_app.permitDoctors_para.Visit_id = 2;
            PermitDoctors form1 = new PermitDoctors();
            form1.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            DoctorMain f = new DoctorMain();
            f.para.Doc_id = abc_app.current_user_personal_info.person_id;
            f.View_Mode = false;
            this.Hide();
            f.ShowDialog();
            this.Show();

        }

        private void button4_Click(object sender, EventArgs e)
        {
            Staff f = new Staff();
            this.Hide();
            f.ShowDialog();
            this.Show();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Finance f = new Finance();
            f.para.Finance_id = abc_app.current_user_personal_info.person_id;
            this.Hide();
            f.ShowDialog();
            this.Show();

        }
    }
}
